﻿using AutoMapper;
using QMERP.Domain.Dtos;
using QMERP.Domain.Entities;

namespace QMERP.Domain.AutoMapper
{
    public class DtoToDomainMappingProfile : Profile
    {
        /// <summary>
        /// 配置构造函数，用来创建关系映射
        /// </summary>
        public DtoToDomainMappingProfile()
        {
            #region App

            CreateMap<AppSaveRequest, App>();

            #endregion

            #region Role

            CreateMap<RoleSaveRequest, Role>();

            #endregion

            #region User

            CreateMap<UserSaveRequest, User>();

            #endregion

            #region Organization

            CreateMap<OrganizationSaveRequest, Organization>();

            #endregion

            #region Supplier

            CreateMap<SupplierSaveRequest, Supplier>();

            #endregion

            #region Currency

            CreateMap<CurrencySaveRequest, Currency>(); 

            #endregion

            #region Dictionary

            CreateMap<DictionaryCategorySaveRequest, DictionaryCategory>();
            CreateMap<DictionarySaveRequest, Dictionary>();

            #endregion

            #region Lens

            CreateMap<LensSaveRequest, Lens>();

            #endregion

            #region Warehouse

            CreateMap<WarehouseSaveRequest, Warehouse>();

            #endregion

            #region EnterStockOrder

            CreateMap<EnterStockOrderSaveRequest, EnterStockOrder>()
                .ForMember(
                   domain => domain.EnterStockOrderDetails,
                   dto => dto.MapFrom(src => src.EnterStockOrderDetails)
                );

            CreateMap<EnterStockOrderDetailSaveRequest, EnterStockOrderDetail>()
                .ForMember(
                   domain => domain.EnterStockOrderDetail_LensDetails,
                   dto => dto.MapFrom(src => src.LensDetails)
                );

            CreateMap<LensDetailResponse, EnterStockOrderDetail_LensDetail>();

            #endregion

            #region LeaveStockOrder

            CreateMap<LeaveStockOrderSaveRequest, LeaveStockOrder>()
                .ForMember(
                   domain => domain.LeaveStockOrderDetails,
                   dto => dto.MapFrom(src => src.LeaveStockOrderDetails)
                );

            CreateMap<LeaveStockOrderDetailSaveRequest, LeaveStockOrderDetail>()
                .ForMember(
                   domain => domain.LeaveStockOrderDetail_LensDetails,
                   dto => dto.MapFrom(src => src.LensDetails)
                );

            CreateMap<LensDetailResponse, LeaveStockOrderDetail_LensDetail>();

            #endregion

            #region PurchaseOrder

            CreateMap<PurchaseOrderSaveRequest, PurchaseOrder>()
                .ForMember(
                   domain => domain.PurchaseOrderDetails,
                   dto => dto.MapFrom(src => src.PurchaseOrderDetails)
                );

            CreateMap<PurchaseOrderDetailSaveRequest, PurchaseOrderDetail>()
                .ForMember(
                   domain => domain.PurchaseOrderDetail_LensDetails,
                   dto => dto.MapFrom(src => src.LensDetails)
                );

            CreateMap<LensDetailResponse, PurchaseOrderDetail_LensDetail>();

            #endregion

            #region TransferOrder

            CreateMap<TransferOrderSaveRequest, TransferOrder>()
                .ForMember(
                   domain => domain.TransferOrderDetails,
                   dto => dto.MapFrom(src => src.TransferOrderDetails)
                );

            CreateMap<TransferOrderDetailSaveRequest, TransferOrderDetail>()
                .ForMember(
                   domain => domain.TransferOrderDetail_LensDetails,
                   dto => dto.MapFrom(src => src.LensDetails)
                );

            CreateMap<LensDetailResponse, TransferOrderDetail_LensDetail>();

            #endregion

            #region TransferLensOrder

            CreateMap<TransferLensOrderSaveRequest, TransferLensOrder>()
                .ForMember(
                   domain => domain.TransferLensOrderDetails,
                   dto => dto.MapFrom(src => src.TransferLensOrderDetails)
                );

            CreateMap<TransferLensOrderDetailSaveRequest, TransferLensOrderDetail>()
                .ForMember(
                   domain => domain.TransferLensOrderDetail_LensDetails,
                   dto => dto.MapFrom(src => src.LensDetails)
                );

            CreateMap<LensDetailResponse, TransferLensOrderDetail_LensDetail>();

            #endregion

            #region InventoryOrder

            CreateMap<InventoryOrderSaveRequest, InventoryOrder>()
                .ForMember(
                   domain => domain.InventoryOrderDetails,
                   dto => dto.MapFrom(src => src.InventoryOrderDetails)
                );

            CreateMap<InventoryOrderDetailSaveRequest, InventoryOrderDetail>()
                .ForMember(
                   domain => domain.InventoryOrderDetail_LensDetails,
                   dto => dto.MapFrom(src => src.LensDetails)
                );

            CreateMap<LensDetailResponse, InventoryOrderDetail_LensDetail>();

            #endregion

            #region LogOperate

            CreateMap<LogOperateAddRequest, LogOperate>();

            #endregion

            #region LogSignIn

            CreateMap<LogSignInAddRequest, LogSignIn>();

            #endregion

            #region Customer

            CreateMap<CustomerSaveRequest, Customer>(); 

            #endregion

            #region Contrac

            CreateMap<ContractSaveRequest, Contract>();
            CreateMap<Contract_LensSaveRequest, Contract_Lens>();
            CreateMap<Contract_Lens_SalesProcessConstraintSaveRequest, Contract_Lens_SalesProcessConstraint>();

            #endregion

            #region RetailOrder

            CreateMap<RetailOrderSaveRequest, RetailOrder>();
            CreateMap<RetailOrderDetailSaveRequest, RetailOrderDetail>();

            #endregion

            #region BulkOrder

            CreateMap<BulkOrderSaveRequest, BulkOrder>()
                .ForMember(
                   dto => dto.BulkOrderDetails,
                   domain => domain.MapFrom(src => src.BulkOrderDetails)
                );

            CreateMap<BulkOrderDetailSaveRequest, BulkOrderDetail>()
                .ForMember(
                   dto => dto.BulkOrderDetail_LensDetails,
                   domain => domain.MapFrom(src => src.LensDetails)
                ).ForMember(
                   dto => dto.BulkOrderDetail_MonofocalMaterialDetails,
                   domain => domain.MapFrom(src => src.BulkOrderDetail_MonofocalMaterialDetails)
                ).ForMember(
                   dto => dto.BulkOrderDetail_BifocalMaterialDetails,
                   domain => domain.MapFrom(src => src.BulkOrderDetail_BifocalMaterialDetails)
                );

            CreateMap<LensDetailResponse, BulkOrderDetail_LensDetail>();

            CreateMap<BulkOrderDetail_MonofocalMaterialDetailSaveRequest, BulkOrderDetail_MonofocalMaterialDetail>();

            CreateMap<BulkOrderDetail_BifocalMaterialDetailSaveRequest, BulkOrderDetail_BifocalMaterialDetail>();

            #endregion
        }
    }
}
